<template>
  <el-dialog class="dia-style" :title="title" :visible.sync="isOpen" width="60%" append-to-body>
    <el-table :data="roleList">
      <el-table-column label="序号" align="center" width="120">
        <template slot-scope="scop">
          {{ scop.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="字段名称" prop="name" :show-overflow-tooltip="true" width="220">
        <template slot-scope="scope">
          <el-input v-if="scope.row.isNew==true" v-model="scope.row.name" placeholder="请输入内容"></el-input>
          <span v-else>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字段类型" prop="productName" :show-overflow-tooltip="true" width="140">
        <template slot-scope="scope">
          <el-select v-if="scope.row.isNew==true" v-model="scope.row.productName" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <span v-else>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否自增" prop="isIncrease">
        <template slot-scope="scope">
          <el-select v-if="scope.row.isNew==true" v-model="scope.row.isIncrease" placeholder="请选择">
            <el-option
              v-for="item in keyWordOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="字段长度" prop="fieldLength" />
      <el-table-column label="自动填充" prop="autoFill"/>
      <el-table-column label="默认值" prop="defaultValue"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.isNew==true"
            size="mini"
            type="text"
                @click="handleDelete(scope.row)"
          >删除
          </el-button>
          <el-button
            v-if="scope.row.name==''"
            size="mini"
            type="text"
            icon="el-icon-delete"
          >弃用
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button style="border:1px dashed #2979ff ;width:100%;" icon="el-icon-plus" @click="handleAddRow">新增一行</el-button>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>

</template>

<script>
import productTable from '@/views/accessProduct/mockData/productTable.json'

export default {
  name: 'upholdDialog',
  props: {
    title: {
      type: String,
      default() {
        return '编辑'
      }
    }
  },
  data() {
    return {
      isOpen: false,
      roleList: [],
      options: [{
        value: '1',
        label: '日期时间类型'
      }, {
        value: '2',
        label: '长整型'
      }, {
        value: '3',
        label: '字符类型'
      }, {
        value: '4',
        label: '字符串类型'
      }],
      keyWordOption: [
        {
          label: '是',
          value: 1
        },
        {
          label: '否',
          value: 0
        }
      ]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.roleList = productTable.list
      this.total = productTable.totalCount
    },
    submitForm() {
      this.$modal.msgSuccess('修改成功')
      this.isOpen = false
    },
    cancel() {
      this.isOpen = false
    },
    handleDelete() {
      console.log('删除数据-----')
    },
    handleAddRow() {
      this.roleList.push({ isNew: true, name: '', productName: '', isIncrease: '' })
    }
  }
}
</script>

<style scoped>

</style>
